package gui.tabs;

import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeListener;

import data.ActionList;
import data.model.Action;

public abstract class AbstractTab extends JPanel implements ActionListener, ChangeListener {
	
	protected JButton newBtn;
	protected JButton editBtn;
	protected JButton remBtn;
	protected JButton savBtn;
	
	protected JTextField tex;
	protected JTextArea texA;
	
	protected Color backColour;
	protected Color uneditColour;
	protected Color listColour;
	
	protected JComboBox combo;
	 
	protected boolean isNew = false;
	protected boolean isEdit = false;
	
	protected JTabbedPane source;
	

	
	public AbstractTab()
	{
		setLayout(new GridLayout(1,5));
		setBackground(backColour);
		backColour = new Color(193,255,193);
		uneditColour = new Color(217,217,217);
		listColour = new Color(224,238,238);
		addComboBox();
		

	}
	
	public void setSrc(JTabbedPane tabs)
	{
		source = tabs;
	}

	protected JTextArea addList(String listName) {
		JPanel listPane = new JPanel();
		listPane.setBackground(backColour);
		
		Border raisedetched = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
		
		Border titled = BorderFactory.createTitledBorder(raisedetched,
				listName,TitledBorder.CENTER,TitledBorder.TOP);
		
		//listPane.setBorder(titled);
		listPane.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		
		c.gridx = 0;
		c.gridy = 0;
		c.weightx = 1;
		c.weighty = 0.2;
		c.fill = GridBagConstraints.BOTH;
		c.insets = new Insets(30,30,30,30);
				
		JTextArea texA = new JTextArea();
		texA.setBackground(listColour);
		texA.setLineWrap(true);
		texA.setEditable(false);

		JScrollPane scrollPane = new JScrollPane(texA);
		scrollPane.setBorder(titled);

		c.weightx = 1;
		c.weighty = 0.8;
		
		listPane.add(scrollPane, c);
		
		this.add(listPane);
		
		return texA;
		
	}


	/**
	 * Add ComboBox for ButtonPane
	 */
	protected abstract void addComboBox();
	
	/**
	 * refreshes contents of combo
	 */
	protected abstract void refreshComboBox();
	
	protected void addInfoPane() {
		JPanel infoPane = new JPanel(new GridBagLayout());
		infoPane.setBackground(backColour);
		
		Border raisedetched = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
		
		//infoPane.setLayout();
		GridBagConstraints c = new GridBagConstraints();
		
		c.gridx = 0;
		c.gridy = 0;
		c.weightx = 0.8;
		c.weighty = 0.2;
		//c.fill = GridBagConstraints.HORIZONTAL;
		
		infoPane.add(new JLabel("Name: "), c);
		
		c.gridx = GridBagConstraints.RELATIVE;
		c.weightx = GridBagConstraints.REMAINDER;
		tex = new JTextField(10);
		tex.setEditable(false);
		tex.setBorder(raisedetched);
		tex.setBackground(uneditColour);
		
		infoPane.add(tex, c);
		
		c.gridx = 0;
		c.gridy = 1;
		c.weightx = 0.5;
		c.weighty = 0.8;
		
		infoPane.add(new JLabel("Notes: "), c);
		
		c.gridx = GridBagConstraints.RELATIVE;
		c.weightx = GridBagConstraints.REMAINDER;
		//c.weighty = GridBagConstraints.REMAINDER;
		
		texA = new JTextArea(10,10);
		texA.setLineWrap(true);
		texA.setEditable(false);
		texA.setBorder(raisedetched);
		texA.setBackground(uneditColour);
		//JScrollPane scrollPane = new JScrollPane(texA);
		
		infoPane.add(texA, c);
		
		this.add(infoPane);
	}

	protected void addButtonPane(String name) {
		JPanel btnPane = new JPanel();
		btnPane.setBackground(backColour);

		btnPane.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		
		c.gridx = 0;
		c.gridy = 0;
		c.weightx = 0.5;
		c.weighty = 0.5;
		
		btnPane.add(new JLabel("Select " + name), c); //top left
		
		c.gridx = 1;
		c.gridy = 0;
		c.weightx = 0.5;
		c.weighty = 0.5;
		//c.gridx =  GridBagConstraints.RELATIVE;
		
		btnPane.add(combo, c); //top right	
		
		c.gridx = 0;
		c.gridy = 1;
		c.weightx = 0.5;
		c.weighty = 0.5;
		
		newBtn = new JButton("new");
		newBtn.addActionListener(this);
		btnPane.add(newBtn, c); //mid left
		
		c.gridx = 1;
		c.gridy = 1;
		c.weightx = 0.5;
		c.weighty = 0.5;
		
		editBtn = new JButton("edit");
		editBtn.addActionListener(this);
		btnPane.add(editBtn, c); //mid right
		
		c.gridx = 0;
		c.gridy = 2;
		c.weightx = 0.5;
		c.weighty = 0.5;
		
		remBtn = new JButton("remove");
		remBtn.addActionListener(this);
		btnPane.add(remBtn, c);	//low left
		
		c.gridx = 1;
		c.gridy = 2;
		c.weightx = 0.5;
		c.weighty = 0.5;
		
		savBtn = new JButton("save");
		savBtn.addActionListener(this);
		btnPane.add(savBtn, c);	//low right

		this.add(btnPane);
	}

	protected abstract void newBtnPressed();

	protected abstract void editBtnPressed();

	protected abstract void remBtnPressed();

	protected abstract void savBtnPressed();

	protected abstract void comboUsed();
}
